package com.bdqn.ch02.repository;

import com.bdqn.ch02.pojo.SysUser;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface SysUserRepository extends JpaRepository<SysUser, Long> {


    List<SysUser> findByUsrName(String usrName);

    List<SysUser> findByUsrNameAndUsrPassword(String usrName,String usrPassword);

    Long countByUsrName(String usrName);

    List<SysUser> findByUsrNameLike(String usrName);

    @Query(value = "select * from sys_user where usr_role_id=?1",nativeQuery = true)
    List<SysUser> findByRoleId(Long roleId);

//    @Query("select u from SysUser u where u.usrRoleId=?1")
//    Page<SysUser> findPageByUsrRoleId(Long roleId, Pageable pageable);

//    Page<SysUser> findAlll(Specification<SysUser> sysUserSpecification);

    Page<SysUser> findAll(Specification<SysUser> sysUserSpecification, Pageable pageable);


//    @Query("select u.usrId as usrId, u.usrName as usrName, u.usrPassword as usrPass" +
//            "word,u.usrRoleId as usrRoleId, u.usrFlag as usrFlag, r.roleName as roleName " +
//            "from SysUser u, Role r where u.usrRoleId=r.roleId and u.usrId=?1")
//    UserInfo getUserInfo(Long useId);
}
